
package xj.graph2d.app.diagram;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenuItem;

import java.util.*;

import xj.model.uml.*;

import xj.graph2d.app.DrawAction;
import xj.graph2d.shapes.uml.ClassShape; 

public class BuildClassDiagramTestListener 
  extends DrawAction 
  implements ActionListener {

  public void actionPerformed(ActionEvent e) {
    if (e != null) { 
      Object src =e.getSource();
      if (src instanceof JMenuItem) { 
	JMenuItem mi = (JMenuItem) src;
	String cmd = mi.getActionCommand(); 
	if ("Class1".equals(cmd)) { 
	  test1();
	} else if ("Class2".equals(cmd)) { 
	  test2(); 
	} else if ("Class3".equals(cmd)) { 
	  test3(); 
	} else if ("Class4".equals(cmd)) { 
	  test4(); 
	} else if ("Class5".equals(cmd)) { 
	  test5(); 
	}
      }
    }
  }

  void test1() { 
    ClassDiagramBuilder builder = new ClassDiagramBuilder(main, "Class Diagram Test1");
    buildDiagram(builder);
    builder.doLayout();
  }

  void test2() { 
    ClassDiagramBuilder builder = new ClassDiagramBuilder(main, "Class Diagram Test2");
    buildDiagram(builder);
    builder.setVertical(false);
    builder.doLayout();
  }

  void test3() { 
    ClassDiagramBuilder builder = new ClassDiagramBuilder(main, "Class Diagram Test3");
    ClassShape cs = builder.addClass("Peter");
    UMLClass cm = (UMLClass) cs.getModel();
    cm.addAttribute(new Attribute("setup", "int")); 
    Operation opr = new Operation();
    opr.setName("XXX");
    opr.setVisibility(Visibility.Public);
    cm.addOperation(opr);
    cs.updateShape();
    builder.doLayout();
  }

  void test4() { 
    ClassDiagramBuilder builder = new ClassDiagramBuilder(main, "Class Diagram Test4");

    builder.doLayout();
  }

  void test5() { 
    ClassDiagramBuilder builder = new ClassDiagramBuilder(main, "Class Diagram Test5");

    builder.doLayout();
  }

  void buildDiagram(ClassDiagramBuilder builder) { 
    builder.addClass("MyClass1");
    builder.addClass("MyClass2");
    builder.addExtention("MyClass1", "MyClass2");

    builder.addClass("MyClass3");
    builder.addAssociation("MyClass1", "MyClass3", "aa");


    builder.addClass("MyClass11");
    builder.addClass("MyClass12");
    builder.addExtention("MyClass11", "MyClass12");

    builder.addClass("MyClass13");
    builder.addAssociation("MyClass11", "MyClass13", "aa", 
			   "role1", Multiplicity.One,
			   "role2", Multiplicity.Many);
    builder.addClass("MyClass14");
    builder.addAssociation("MyClass12", "MyClass14", "bb");


    builder.addClass("MyClass21");
    builder.addClass("MyClass22");
    builder.addClass("MyClass23");
    builder.addExtention("MyClass22", "MyClass21");
    builder.addExtention("MyClass23", "MyClass21");

    builder.addClass("MyClass24");
    builder.addAssociation("MyClass21", "MyClass24", "aa", false, false);
    builder.addClass("MyClass25");
    builder.addAssociation("MyClass22", "MyClass25", "bb", true, false);
    builder.addClass("MyClass26");
    builder.addAssociation("MyClass23", "MyClass26", "cc", true, true);


    builder.addClass("MyClass31");
    builder.addClass("MyClass32");
    builder.addClass("MyClass33");
    builder.addExtention("MyClass32", "MyClass31");
    builder.addExtention("MyClass33", "MyClass32");

    builder.addClass("MyClass34");
    builder.addAssociation("MyClass31", "MyClass34", "aa");
    builder.addClass("MyClass35");
    builder.addAssociation("MyClass32", "MyClass35", "bb");
    builder.addClass("MyClass36");
    builder.addAssociation("MyClass33", "MyClass36", "cc");

    builder.addClass("MyClass41");
    builder.addClass("MyClass42");
    builder.addClass("MyClass43");
    builder.addClass("MyClass47");
    builder.addExtention("MyClass42", "MyClass41");
    builder.addExtention("MyClass43", "MyClass42");
    builder.addExtention("MyClass47", "MyClass41");

    builder.addClass("MyClass44");
    builder.addAssociation("MyClass41", "MyClass44", "aa");
    builder.addClass("MyClass45");
    builder.addAssociation("MyClass42", "MyClass45", "bb");
    builder.addClass("MyClass46");
    builder.addAssociation("MyClass43", "MyClass46", "cc");
    builder.addClass("MyClass48");
    builder.addAssociation("MyClass47", "MyClass48", "dd");

    
    builder.addClass("MyClass100");
    builder.addClass("MyClass101");
    builder.addClass("MyClass102");
    builder.addExtention("MyClass101", "MyClass100");
    builder.addExtention("MyClass102", "MyClass100");

    builder.addClass("MyClass200");
    builder.addClass("MyClass201");
    builder.addClass("MyClass202");
    builder.addClass("MyClass203");
    builder.addExtention("MyClass201", "MyClass200");
    builder.addExtention("MyClass202", "MyClass200");
    builder.addExtention("MyClass203", "MyClass200");

    builder.addClass("MyClass300");
    builder.addClass("MyClass301");
    builder.addClass("MyClass302");
    builder.addClass("MyClass303");
    builder.addClass("MyClass304");
    builder.addExtention("MyClass301", "MyClass300");
    builder.addExtention("MyClass302", "MyClass300");
    builder.addExtention("MyClass303", "MyClass300");
    builder.addExtention("MyClass304", "MyClass300");

    builder.addClass("MyClass400");
    builder.addClass("MyClass401");
    builder.addClass("MyClass402");
    builder.addClass("MyClass403");
    builder.addClass("MyClass404");
    builder.addClass("MyClass405");
    builder.addExtention("MyClass401", "MyClass400");
    builder.addExtention("MyClass402", "MyClass400");
    builder.addExtention("MyClass403", "MyClass400");
    builder.addExtention("MyClass404", "MyClass400");
    builder.addExtention("MyClass405", "MyClass400");

    builder.addClass("MyClass500");
    builder.addClass("MyClass501");
    builder.addClass("MyClass502");
    builder.addClass("MyClass503");
    builder.addClass("MyClass504");
    builder.addClass("MyClass505");
    builder.addClass("MyClass506");
    builder.addExtention("MyClass501", "MyClass500");
    builder.addExtention("MyClass502", "MyClass500");
    builder.addExtention("MyClass503", "MyClass500");
    builder.addExtention("MyClass504", "MyClass500");
    builder.addExtention("MyClass505", "MyClass500");
    builder.addExtention("MyClass506", "MyClass500");

    builder.addClass("MyClass600");
    builder.addClass("MyClass601");
    builder.addClass("MyClass602");
    builder.addClass("MyClass603");
    builder.addClass("MyClass604");
    builder.addClass("MyClass605");
    builder.addClass("MyClass606");
    builder.addClass("MyClass607");
    builder.addExtention("MyClass601", "MyClass600");
    builder.addExtention("MyClass602", "MyClass600");
    builder.addExtention("MyClass603", "MyClass600");
    builder.addExtention("MyClass604", "MyClass600");
    builder.addExtention("MyClass605", "MyClass600");
    builder.addExtention("MyClass606", "MyClass600");
    builder.addExtention("MyClass607", "MyClass600");
  }

}
